package com.hustzp.com.xichuangzhu.me;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.hustzp.com.xichuangzhu.R;

/**
 * Created by Administrator on 2016/6/5.
 */
public class MyStarActivity extends MyBaseActivity {

    private Button worksBtn;
    private Button quoteBtn;

    private ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_star);

        initViews();
    }

    public void clickView(View view) {
        switch (view.getId()) {
            case R.id.switch_works_btn:
                // 样式
                worksBtn.setTextColor(Color.WHITE);
                worksBtn.setBackgroundResource(R.drawable.round_menu_left_selected);

                quoteBtn.setTextColor(getResources().getColor(R.color.c_046aae));
                quoteBtn.setBackgroundResource(R.drawable.round_menu_right);

                mViewPager.setCurrentItem(0);
                break;
            case R.id.switch_quote_btn:
                // 样式
                quoteBtn.setTextColor(Color.WHITE);
                quoteBtn.setBackgroundResource(R.drawable.round_menu_right_selected);

                worksBtn.setTextColor(getResources().getColor(R.color.c_046aae));
                worksBtn.setBackgroundResource(R.drawable.round_menu_left);

                mViewPager.setCurrentItem(1);
                break;
        }
    }

    private void initViews() {
        final TextView actionText = (TextView) findViewById(R.id.tv_action_txt);
        actionText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (actionText.getTag() == null) {
                    actionText.setText("完成");
                    actionText.setTag(1);
                } else {
                    actionText.setText("管理");
                    actionText.setTag(null);
                }

                mViewPager.getAdapter().notifyDataSetChanged();
            }
        });

        worksBtn = (Button) findViewById(R.id.switch_works_btn);
        quoteBtn = (Button) findViewById(R.id.switch_quote_btn);

        mViewPager = (ViewPager) findViewById(R.id.view_pager_like);
        mViewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

            @Override
            public Fragment getItem(int position) {
                Fragment fragment = null;
                switch (position) {
                    case 0:
                        fragment = new LikeWorksFragment();
                        break;
                    case 1:
                        fragment = new LikeQuoteFragment();
                        break;
                }

                Bundle bundle = new Bundle();
                bundle.putBoolean("isDelMode", actionText.getTag() == null ? false : true);
                fragment.setArguments(bundle);

                return fragment;
            }

            @Override
            public int getItemPosition(Object object) {
                return POSITION_NONE;
            }

            @Override
            public int getCount() {
                return 2;
            }
        });

        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        worksBtn.setTextColor(Color.WHITE);
                        worksBtn.setBackgroundResource(R.drawable.round_menu_left_selected);

                        quoteBtn.setTextColor(getResources().getColor(R.color.c_046aae));
                        quoteBtn.setBackgroundResource(R.drawable.round_menu_right);
                        break;
                    case 1:
                        quoteBtn.setTextColor(Color.WHITE);
                        quoteBtn.setBackgroundResource(R.drawable.round_menu_right_selected);

                        worksBtn.setTextColor(getResources().getColor(R.color.c_046aae));
                        worksBtn.setBackgroundResource(R.drawable.round_menu_left);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


}
